<#include "/admin/_inc/_head.html"/>
<#include "/admin/_inc/_layout.html" />
<!DOCTYPE html>
<html lang="en">

<head>
    <@head />

</head>

<body>
<@layout>

<div class="row">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5> <small></small></h5>

            </div>
            <div class="ibox-content">
                <form id="form" action="${ctx_admin}/account/updatepwd" method="post" class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">新密码</label>

                        <div class="col-sm-10">
                            <input id="password" name="password" type="password" class="form-control" required="" aria-required="true">
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">确认密码</label>
                        <div class="col-sm-10">
                            <input id="password2" name="password2" type="password" class="form-control" required="" aria-required="true">
                            <#--<span class="help-block m-b-none">帮助文本，可能会超过一行，以块级元素显示</span>-->
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-2">
                            <button class="btn btn-primary" type="submit">提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


</@layout>
<script src="/assets/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/assets/js/plugins/validate/messages_zh.min.js"></script>
<script src="/assets/js/plugins/jquery.form/jquery.form.js"></script>
<script type="text/javascript">
    $.validator.setDefaults({
        highlight: function (e) {
            $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
        }, success: function (e) {
            e.closest(".form-group").removeClass("has-error").addClass("has-success")
        }, errorElement: "span", errorPlacement: function (e, r) {
            e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
        }, errorClass: "help-block m-b-none", validClass: "help-block m-b-none"
    });
    // 密码验证正则表达式
    $.validator.addMethod("regexPassword", function(value, element) {
        return this.optional(element) || /^(?=^.{6,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/.test(value);
    }, "密码至少包一个大写字母、一个小写字母及一个符号，长度至少6位");

    $(function () {
        var e = "<i class='fa fa-times-circle'></i> ";
        $("#form").validate({
            messages: {
                // password: e + "请输入新密码",
                // password2: e + "请输入确认密码"
            },
            rules: {
                password: {
                    required:true,
                    rangelength: [6, 15],
                    regexPassword:true
                },
                password2: {
                    required: true,
                    rangelength: [6, 15],
                    regexPassword:true,
                    equalTo: "#password"
                }
            },
            submitHandler:function(form){
                $(form).ajaxSubmit({
                    url:form.action,
                    dataType: 'json',
                    success: function (res) {
                        if(res.success){
                            layer.msg(res.message, {icon: 1,time: 2000 }, function(){
                                location.href='/logout';
                                location.reload();
                            });
                        }else{
                            layer.msg(res.message, {icon: 2,time: 3000 }, function(){});
                        }

                    },
                    error: function () {
                        layer.msg('系统错误', {icon: 2,time: 3000 }, function(){});
                    }
                });

            }
        });
    }) ;

</script>


</body>

</html>